package com.fx.test.treeview;

import java.util.Arrays;

import com.oim.fx.common.box.ImageBox;
import com.oim.fx.ui.component.IconButton;
import com.oim.fx.ui.list.HeadItem;

import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.stage.Stage;

/**
 * @author: XiaHui
 * @date: 2017年4月10日 上午11:02:59
 */
public class TreeViewApp extends Application {

	public Parent createContent() {

		final TreeItem<String> treeRoot = new TreeItem<String>("Root node");

		treeRoot.getChildren().addAll(Arrays.asList(
				new TreeItem<String>("Child Node 1"),
				new TreeItem<String>("Child Node 2"),
				new TreeItem<String>("Child Node 3")));

		treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(

				new TreeItem<String>("Child Node 4"),
				new TreeItem<String>("Child Node 5"),
				new TreeItem<String>("Child Node 6"),
				new TreeItem<String>("Child Node 7"),
				new TreeItem<String>("Child Node 8")));

		HeadItem head = new HeadItem();
		Image image = ImageBox.getImagePath("Resources/Images/Head/User/" + 1 + ".png", 40, 40);
		head.setHeadImage(image);
		head.setRemark("女神经" + (11111));
		head.setNickname("(哈加额)");
		head.setStatus("[2G]");
		head.setShowText("哈哈哈，又有新闻了");

		Image iconImage = ImageBox.getImagePath("Resources/Images/Default/Status/FLAG/Big/imonline.png");
		IconButton iconButton = new IconButton(iconImage);
		head.addBusinessIcon(iconButton);
		
		head.setOnMouseEntered(e->{
			System.out.println(3333);
		});

		

		TreeItem<HeadItem> root = new TreeItem<HeadItem>(head);
		
	
		
		head = new HeadItem();
		image = ImageBox.getImagePath("Resources/Images/Head/User/" + 1 + ".png", 40, 40);
		head.setHeadImage(image);
		head.setRemark("女神经" + (11111));
		head.setNickname("(哈加额)");
		head.setStatus("[2G]");
		head.setShowText("哈哈哈，又有新闻了");

		iconImage = ImageBox.getImagePath("Resources/Images/Default/Status/FLAG/Big/imonline.png");
		iconButton = new IconButton(iconImage);
		head.addBusinessIcon(iconButton);
		
		TreeItem<HeadItem> node = new TreeItem<HeadItem>(head);
		
		root.getChildren().add(node);
		

		TreeView<HeadItem> treeView = new TreeView<HeadItem>();
		treeView.setShowRoot(true);
		treeView.setRoot(root);
		// treeRoot.setExpanded(true);
		
		treeView.setOnMouseEntered(e->{
			System.out.println(1111);
		});

		return treeView;

	}

	@Override

	public void start(Stage primaryStage) throws Exception {

		primaryStage.setScene(new Scene(createContent()));

		primaryStage.show();

	}

	/**
	 * 
	 * Java main for when running without JavaFX launcher
	 * 
	 */

	public static void main(String[] args) {

		launch(args);

	}

}